# working institution:School of Mathematical Sciences,Zhejiang University
# author:Kangjie Ding
# date:2022/11/16 20:12
import pygame
from pygame.sprite import Sprite

class Bullet(Sprite):
    """管理所有子弹的类"""
    def __init__(self,ai_game):
        """在飞船当前位置创建一个子弹"""
        super().__init__()
        self.screen=ai_game.screen
        self.settings=ai_game.settings
        self.color=ai_game.settings.bullet_color
        #在（0，0）出创建一个子弹矩形，并将其移至飞船子弹发射处
        self.rect=pygame.Rect(0,0,self.settings.bullet_width,
                              self.settings.bullet_height)
        self.rect.midtop=ai_game.ship.rect.midtop

    def update(self):
        """更新子弹位置"""
        self.rect.y-=self.settings.bullet_speed

    def draw_bullet(self):
        """显示子弹"""
        pygame.draw.rect(self.screen,self.color,self.rect)